<html>
<head><meta charset="utf-8"><title>Interaction between type-ascription and named arguments · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Interaction.20between.20type-ascription.20and.20named.20arguments.html">Interaction between type-ascription and named arguments</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215246905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Interaction%20between%20type-ascription%20and%20named%20arguments/near/215246905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Poliorcetics <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Interaction.20between.20type-ascription.20and.20named.20arguments.html#215246905">(Nov 01 2020 at 14:40)</a>:</h4>
<p>Hello <a class="stream" data-stream-id="131828" href="/#narrow/stream/131828-t-compiler">#t-compiler</a> !</p>
<p>I'm currently writing a RFC for named arguments and I'm not sure if the syntax I'm leaning towards at the moment will be problematic or not so I'm here to ask about it and ensures the whole thing won't come crashing down seconds after I make the PR (which will not come soon <em>at all</em>).</p>
<p>My current idea is to use <code>:</code> because that's what is used when instantiating <code>struct</code>s but from what I read about type ascription it could pose problems in the future and type ascription seems more important so I don't want to interfere with it.</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">open_port</span><span class="p">(</span><span class="n">port</span>: <span class="kt">u32</span><span class="p">,</span><span class="w"> </span><span class="n">with_max_conn</span><span class="w"> </span><span class="n">max_connexions</span>: <span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="k">pub</span><span class="w"> </span><span class="n">timeout</span>: <span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"Port: {}</span><span class="se">\n</span><span class="s">Max connexions: {}</span><span class="se">\n</span><span class="s">Timeout: {}"</span><span class="p">,</span><span class="w"> </span><span class="n">port</span><span class="p">,</span><span class="w"> </span><span class="n">max_connexions</span><span class="p">,</span><span class="w"> </span><span class="n">timeout</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// Called as:</span>
<span class="n">open_port</span><span class="p">(</span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="n">with_max_conn</span>: <span class="mi">10</span><span class="p">,</span><span class="w"> </span><span class="n">timeout</span>: <span class="mi">200</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>The possible problem is that I think type ascription is supposed to be used like <code>expr: type</code> so the following interaction would exist:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">open_port</span><span class="p">(</span><span class="mi">12345</span><span class="p">,</span><span class="w"> </span><span class="n">with_max_conn</span>: <span class="nc">my_func</span><span class="p">()</span>: <span class="kt">usize</span><span class="p">,</span><span class="w"> </span><span class="n">timeout</span>: <span class="nc">my_timeout_var</span>: <span class="kt">usize</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>I'm not sure if this is a problem. To me <code>with_max_conn</code> and <code>timeout</code> are labels, not expressions so type ascription should never be considered as applicable for them and I'm not sure type ascription would even be ever needed here outside of a generic type conforming to some trait.</p>
<p>So my question really is: would the syntax proposed in the code block just above work (in theory) ? Or is it impossible/way too hard to implement ?</p>



<a name="215283270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Interaction%20between%20type-ascription%20and%20named%20arguments/near/215283270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Interaction.20between.20type-ascription.20and.20named.20arguments.html#215283270">(Nov 02 2020 at 06:34)</a>:</h4>
<p>On type ascription you might be interested in this thread: <a href="#narrow/stream/213817-t-lang/topic/type.20ascription/near/213852443">https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/type.20ascription/near/213852443</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>